// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SLAM2DAgentMessage.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Microsoft.Robotics.Navigation.Runtime.Localization
{
    using System.Runtime.Serialization;

    using Microsoft.Robotics.Hardware.DAC;
    using Microsoft.Robotics.Navigation.Localization;
    using Microsoft.Robotics.Numerics;
    using Microsoft.Robotics.Runtime;

    /// <summary>
    /// Message type for SLAM2DAgent
    /// </summary>
    [DataContract]
    public class SLAM2DAgentMessage : AgentMessage
    {
        /// <summary>
        /// Initializes a new instance of the SLAM2DAgentMessage class
        /// </summary>
        /// <param name="map">The global map.</param>
        /// <param name="mostLikelyLocation">The current estimate for the robot location</param>
        /// <param name="alternatePoses">The other plausible robot poses</param>
        /// <param name="particles">The particles maintained by the particle filter</param>
        /// <param name="initiatingMessage">
        /// The lower-level message that triggered the creation of this message (e.g. a HorizontalDepthProfileMessage is created as a result of a DepthMessage).
        /// The constructor copies the originatingTime from the initiatingMessage to this message, to allow synchronization of messages that have the same real-world origin.
        /// </param>
        internal SLAM2DAgentMessage(GlobalMap map, Pose2D mostLikelyLocation, Pose2D[] alternatePoses, SLAM2DParticle[] particles, AgentMessage initiatingMessage)
            : this(map, mostLikelyLocation, alternatePoses, particles, initiatingMessage.OriginatingTime)
        {
        }

        /// <summary>
        /// Initializes a new instance of the SLAM2DAgentMessage class
        /// </summary>
        /// <param name="map">The global map.</param>
        /// <param name="mostLikelyLocation">The current estimate for the robot location</param>
        /// <param name="alternatePoses">The other plausible robot poses</param>
        /// <param name="particles">The particles maintained by the particle filter</param>
        /// <param name="originatingTime">The time when the hardware generated the event or data that led to this message being created.</param>
        internal SLAM2DAgentMessage(GlobalMap map, Pose2D mostLikelyLocation, Pose2D[] alternatePoses, SLAM2DParticle[] particles, long originatingTime)
            : base(originatingTime)
        {
            this.Map = map;
            this.Location = mostLikelyLocation;
            this.Poses = alternatePoses;
            this.Particles = particles;
        }

        /// <summary>
        /// Gets the most likely robot pose
        /// </summary>
        [DataMember]
        public Pose2D Location { get; private set; }

        /// <summary>
        /// Gets the poses tracked by the particle filter.
        /// </summary>
        public Pose2D[] Poses { get; private set; }

        /// <summary>
        /// Gets the most likely global occupancy grid map 
        /// </summary>
        public GlobalMap Map { get; private set; }

        /// <summary>
        /// Gets the particles maintained by the particle filter
        /// </summary>
        public SLAM2DParticle[] Particles { get; private set; }
    }
}
